package com.bys.controller;

import com.bys.entity.User;
import com.bys.service.IUserService;
import com.bys.vo.UserVo;
import org.example.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.example.util.PageResult;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bys
 * @since 2025-01-07
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;
    @RequestMapping("/list")
    public R findAll(){
        return R.ok().data("users",userService.list());
    }
    @GetMapping("/findByPage/{page}/{pageSize}")
    public R findByPage(@PathVariable("page") Integer page,
                        @PathVariable("pageSize") Integer pageSize){
        PageResult<User> users = userService.findByPage(page,pageSize);
        System.out.println(users);
        return R.ok().data("users",users);
    }
    @PostMapping("/search/{page}/{pageSize}")
    public R search(@PathVariable("page") Integer page,
                    @PathVariable("pageSize") Integer pageSize,
                    @RequestBody(required = false) UserVo vo){
        PageResult<User> users = userService.search(page,pageSize,vo);
        return R.ok().data("users",users);
    }
}
